//#ifdef MP-WEIXIN
import cookies from '../vendor/weapp-cookie/dist/weapp-cookie';
//#endif
function loginOut() {
    let uid = getApp().globalData.uid;

    if (uid) {
        getApp().globalData.uid = '';
        getApp().globalData.avatar = '';
        getApp().globalData.username = '';
        uni.removeStorageSync('uid');
        let cookiepre = uni.getStorageSync('cookiepre');
        let authKey = cookiepre + 'auth';
//#ifdef MP-WEIXIN
        if (cookies.has(authKey)) {
            cookies.remove(authKey);
        }
        //#endif
    }
}

function loginSetUserInfo(obj) {
    uni.setStorageSync('uid', obj.Variables.member_uid);
    getApp().globalData.uid = obj.Variables.member_uid;
    getApp().globalData.avatar = obj.Variables.member_avatar;
    getApp().globalData.username = obj.Variables.member_username;
}

function isLogin() {
    if (getApp().globalData.uid) {
        return true;
    }

    toLogin();
    return false;
}

function toLogin() {
    uni.navigateTo({
        url: '/pages/login/login'
    });
}

var openid = '';
var unionid = '';
module.exports = {
    loginOut: loginOut,
    loginSetUserInfo: loginSetUserInfo,
    isLogin: isLogin,
    toLogin: toLogin,
    openid: openid,
    unionid: unionid
};
